package org.example.book.config;

import lombok.extern.slf4j.Slf4j;
import org.example.book.model.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@Slf4j
@ResponseBody
@ControllerAdvice
public class ExceptionAdvice {
    @ExceptionHandler
    public Result handlerException(Exception e){
        log.error("发生异常e:",e);
        return Result.fail(e.getMessage());
    }
    @ExceptionHandler
    public Result handlerException(NullPointerException e){
        log.error("发生异常e:",e);
        return Result.fail("空指针异常");
    }
    @ExceptionHandler
    public Result handlerException(ArithmeticException e){
        log.error("发生异常e:",e);
        return Result.fail("算数异常");
    }

}
